package com.zzyl.controller.security;

import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.vo.MenuVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/resource")
@Api(tags = "资源管理")
public class ResourceController {

    @Autowired
    private ResourceService resourceService;

    //TODO @ApiOperation("资源列表")
    @PostMapping("/list")
    public ResponseResult<List<ResourceVo>> selectlist(@RequestBody ResourceDto dto) {
        List<ResourceVo> vos = resourceService.selectlist(dto);
        return ResponseResult.success(vos);
    }

    //TODO @ApiOperation("资源树形")
    @PostMapping("/tree")
    public ResponseResult<TreeVo> responseTree(@RequestBody ResourceDto dto) {
        TreeVo vos = resourceService.resourceTreeVo(dto);
        return ResponseResult.success(vos);
    }

    //TODO @ApiOperation("资源添加")
    @PutMapping
    public ResponseResult<Void> addresponse(@RequestBody ResourceDto dto) {
        resourceService.addresponse(dto);
        return ResponseResult.success();
    }

    //TODO @ApiOperation("资源修改")
    @PatchMapping
    public ResponseResult<Void> updateresource(@RequestBody ResourceDto dto) {
        resourceService.updateresource(dto);
        return ResponseResult.success();
    }

    //TODO @ApiOperation("启用禁用")
    @PostMapping("/enable")
    public ResponseResult<Void> enable(@RequestBody ResourceDto dto) {
        resourceService.enable(dto);
        return ResponseResult.success();
    }
    //TODO @ApiOperation("删除菜单")
    @DeleteMapping("{menuId}")
    public ResponseResult<Void> deleteresource(@PathVariable String menuId){
        resourceService.deletesource(menuId);
        return ResponseResult.success();
    }
    ////////////////////////////////////////////////////////////////////////////////////

    @GetMapping("/menus")
    @ApiOperation("我的菜单")
    public ResponseResult<List<MenuVo>> getMyMenus() {
        log.info("我的菜单");
        List<MenuVo> menus = resourceService.getMyMenus();
        return ResponseResult.success(menus);
    }
}
